﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Sio.Mdm.Server.ServerCommands
{
    public class ChangePassword : Administration.ServerCommand
    {
        #region Construction
        public ChangePassword()
            : base("changepass")
        {
        } 
        #endregion

        #region IServerCommand Members
        public override string Description
        {
            get 
            {
                return "Change administration password for remote administration.";
            }
        }
        public override bool Execute()
        {   
            if(Parameters.Length < 2)
            {
                throw new ArgumentException("You must supply old and new password");
            }

            string oldPass = Sio.Mdm.Server.Server.EncodePassword(Parameters[0]);

            if (oldPass == Config.RemotePassword)
            {
                Config.RemotePassword =
                    Sio.Mdm.Server.Server.EncodePassword(Parameters[1]);
                Config.Save();

                Result = "Password change succeded";
                return true;
            }            

            return false;
        }
        #endregion
    }
}
